home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / VideoToolboxSources / TranslateLinefeeds.h < prev    next >
Text File  |  1993-12-14  |  3KB  |  82 lines

  1. /* TranslateLinefeeds.h
  2. This header should be included in all THINK C files that may use the MPW C
  3. stdio library. It intercepts all i/o calls to the stdio library (except scanf
  4. and fscanf), causing them to go through TranslateLinefeeds.c, which, if the i/o
  5. is to a text (i.e. not binary) stream, interposes the filtering function 
  6. TranslateLinefeeds to exchange /n and /r, between the caller and the (MPW) 
  7. stdio library.
  8.  
  9. VideoToolbox.h automatically includes TranslateLinefeeds.h if
  10. MATLAB is true.
  11. */
  12. #pragma once
  13. #define _TranslateLinefeeds_
  14. #include <stdio.h>
  15. #include <stdarg.h>
  16.  
  17. /*
  18. The following typedef and define are copied from the MPW C 3.2 StdIO.h header file,
  19. adding the prefix "MPW_". It is essential that they match the version used by MATLAB.
  20. */
  21. typedef struct {
  22.     long int         _cnt;    /* dgp: added "long" */
  23.     unsigned char    *_ptr;
  24.     unsigned char    *_base;
  25.     unsigned char    *_end;
  26.     unsigned short    _size;
  27.     unsigned short    _flag;
  28.     unsigned short    _file;
  29. } MPW_FILE;
  30. #define MPW_IOBINARY    (1<<9)        /* Binary stream */
  31.  
  32. #if MATLAB
  33.     /* Use MPW C's FILE struct */
  34.     #define IS_TEXT(stream) !(((MPW_FILE *)(stream))->_flag&MPW_IOBINARY)
  35. #else
  36.     /* Use THINK C's FILE struct */
  37.     #define IS_TEXT(stream) !(stream)->binary
  38. #endif
  39.  
  40. int fgetcTL(FILE *stream);
  41. char *fgetsTL(char *string,int n,FILE *stream);
  42. int fprintfTL(FILE *stream,const char *format,...);
  43. int fputsTL(char *string,FILE *stream);
  44. int printfTL(char *format,...);
  45. void TranslateLinefeeds(char *string,size_t n);
  46. int vfprintfTL(FILE *stream,const char *format,va_list args);
  47. int vprintfTL(char *format,va_list args);
  48. size_t freadTL(void *s,size_t size,size_t numitems,FILE *stream);
  49. size_t fwriteTL(void *s,size_t size,size_t numitems,FILE *stream);
  50. char *getsTL(char *string);
  51. int fputcTL(int ch,FILE *stream);
  52. extern unsigned char translateLinefeed[256];
  53.  
  54. #define getc_STD getc
  55. #define getchar_STD getchar
  56. #define putc_STD putc
  57. #define putchar_STD putchar
  58. #define ungetc_STD ungetc
  59. #undef getc
  60. #undef getchar
  61. #undef printf    /* discard cmex.h definition */
  62. #undef putc
  63. #undef putchar
  64. #undef ungetc
  65. #define fgetc(stream) fgetcTL(stream)
  66. #define fgets fgetsTL
  67. #define fprintf fprintfTL
  68. #define fputc fputcTL
  69. #define fputs fputsTL
  70. #define fread freadTL
  71. #define fwrite fwriteTL
  72. #define getc(stream) (IS_TEXT(stream)?(int)translateLinefeed[(unsigned char)getc_STD(stream)]:getc_STD(stream))
  73. #define getchar() ((int)translateLinefeed[(unsigned char)getchar_STD()])
  74. #define gets getsTL
  75. #define printf printfTL
  76. #define putc(c,stream) putc_STD(IS_TEXT(stream)?translateLinefeed[(unsigned char)c]:c,stream)
  77. #define putchar(c) putchar_STD(translateLinefeed[(unsigned char)(c)])
  78. #define puts(string) fputsTL(string,stdout)
  79. #define ungetc(c,stream) ungetc_STD(IS_TEXT(stream)?translateLinefeed[(unsigned char)c]:c,stream)
  80. #define vfprintf vfprintfTL
  81. #define vprintff vprintfTL
  82.